import { ElMessage } from "element-plus";

const allowImageFormat = [
  "image/jpeg",
  "image/jpg",
  "image/png",
  "image/webp",
  "image/gif",
];

const allowVideoFormat = ["video/mp4", "video/avi", "video/mov", "video/mpeg"];

export const imgBeforeUpload = (rawFile) => {
  if (!allowImageFormat.includes(rawFile.type)) {
    ElMessage.error("上传图片只能是 JPEG/JPG/PNG/WEBP/GIF 格式!");
    return false;
  }
  if (rawFile.size / 1024 / 1024 > 2) {
    ElMessage.error("单张图片大小不能超过 2MB!");
    return false;
  }
  return true;
};

export const videoBeforeUpload = (rawFile: any) => {
  if (!allowVideoFormat.includes(rawFile.type)) {
    ElMessage.error("上传图片只能是 MP4/AVI/MOV/MPEG 格式!");
    return false;
  }
  if (rawFile.size / 1024 / 1024 > 200) {
    ElMessage.error("单张图片大小不能超过 200MB!");
    return false;
  }
  return true;
};
